package com.xhui.vimarket.zkplus.ui.id;

import java.util.Iterator;
import java.util.List;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Page;
import org.zkoss.zk.ui.ext.BeforeCompose;
import org.zkoss.zk.ui.http.SerializableUiFactory;
import org.zkoss.zk.ui.metainfo.ComponentInfo;
import org.zkoss.zk.ui.metainfo.Property;
import org.zkoss.zul.Window;

public class CrmUiFactory extends SerializableUiFactory {
    public Component newComponent(Page page, Component parent,
        ComponentInfo compInfo) {
            final Component comp = compInfo.newInstance(page, parent);
            List list = compInfo.getProperties();
            
            //设置_id属性。
            for (Iterator it = list.iterator(); it.hasNext();) {
                Property p = (Property)it.next();
                if ("id".equals(p.getName())) {
                    //对窗体通过属性处理。
                    if (comp instanceof Window) {
                        comp.setAttribute(ZKRebuildUuid.CRM2ID, p.getRawValue());
                    } else {
                        p.assign(comp);
                    }
                    break;
                } 
            }  
            if (parent != null) comp.setParent(parent);
            else comp.setPage(page);

            if (comp instanceof BeforeCompose)
                ((BeforeCompose)comp).beforeCompose();
            compInfo.applyProperties(comp); //include comp's definition
            return comp;
        }
}
